//
//  CHSatisfactionCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/9/21.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHSatisfactionCell.h"
#import "CHPieChartView.h"
#import "PiechartModel.h"
@interface CHSatisfactionCell ()
{
    CHPieChartView *chartView;
    UILabel *goodLabel;
    UILabel *verygoodLabel;
    UILabel *badLabel;
}

@end
@implementation CHSatisfactionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHSatisfactionCell";
    CHSatisfactionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[CHSatisfactionCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
    
    chartView = [[CHPieChartView alloc]initWithFrame:CGRectMake(30, 30,100, 100) withStrokeWidth:30  andAnimation:YES];
    [self addSubview:chartView];
    
    
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(180, 30, 20,20)];
    blueView.backgroundColor = KRGB(89, 154, 230);
    [self addSubview:blueView];
    
    verygoodLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(blueView.frame) +5, 25, UIScreenW - CGRectGetMaxX(blueView.frame) -5, 30)];
    verygoodLabel.text = @"非常满意 0.0%";
    verygoodLabel.font = [UIFont systemFontOfSize:14];
    verygoodLabel.textColor = KRGB(89, 154, 230);
    [self addSubview:verygoodLabel];
    
    
    UIView *orangeView = [[UIView alloc] initWithFrame:CGRectMake(180, 70, 20, 20)];
    orangeView.backgroundColor = [UIColor orangeColor];
    [self addSubview:orangeView];
    
    goodLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(blueView.frame) +5, CGRectGetMaxY(verygoodLabel.frame) +10, UIScreenW - CGRectGetMaxX(blueView.frame)-5, 30)];
    goodLabel.textColor = [UIColor orangeColor];
    goodLabel.text = @"满意 0.0%";
    goodLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:goodLabel];
    
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(180, 110, 20, 20)];
    greenView.backgroundColor = [UIColor greenColor];
    [self addSubview:greenView];
    
    badLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(blueView.frame) +5, CGRectGetMaxY(goodLabel.frame) +10, UIScreenW - CGRectGetMaxX(blueView.frame) - 5, 30)];
    badLabel.textColor = [UIColor greenColor];
    badLabel.text = @"不满意 0.0%";
    badLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:badLabel];
}


-(void)setModel:(QYDetailModel *)model{
    _model = model;
    
    PiechartModel *model1 = [[PiechartModel alloc]init];
    model1.color = KRGB(89, 154, 230);
    model1.perStr = model.verygood;
    
    PiechartModel *model2 = [[PiechartModel alloc]init];
    model2.color = [UIColor orangeColor];
    model2.perStr = model.good;
    
    PiechartModel *model3 = [[PiechartModel alloc]init];
    model3.color = [UIColor greenColor];
    model3.perStr =  model.bad;
    
    NSArray *perArry = [NSArray arrayWithObjects:model1,model2,model3, nil];
    chartView.perArray = perArry;
    
    
    verygoodLabel.text = [NSString stringWithFormat:@"非常满意 %.f%%",[model.verygood floatValue] *100];
    goodLabel.text = [NSString stringWithFormat:@"满意 %.f%%",[model.good floatValue] *100];
    badLabel.text = [NSString stringWithFormat:@"不满意 %.f%%",[model.bad floatValue] *100];
    
    
}

@end
